package com.woniuxy.listener;

import com.woniuxy.entity.SessionMessages;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Author: 马宇航
 * @Todo: 模拟，用户同一笔订单，触发了3次支付请求
 * @DateTime: 25/08/29/星期五 17:37
 * @Component: 成都蜗牛学苑
 **/
@Component
public class EmailListener {
    @Autowired
    StringRedisTemplate redisTemplate;
    @RabbitListener(queues = "fanout.email.queue1")
    public void receive(String orderNum) {
        if (checkOrderFromRedis(orderNum)){
            System.out.println("EmailListener.receive: 订单支付中……");
        }else {
            System.out.println("EmailListener.receive: 订单重复支付，发送邮件");
        }
    }
    @RabbitListener(queues = "fanout.message.queue2")
    public void fanoutMessage(String orderNum) {
        if (checkOrderFromRedis(orderNum)){
            System.out.println("EmailListener.fanoutMessage: 订单支付中……");
        }else {
            System.out.println("EmailListener.fanoutMessage: 订单重复支付，发送邮件");
        }
    }
    @RabbitListener(queues = "fanout.pay.queue3")
    public void fanoutPayMessage(String orderNum) {
        if (checkOrderFromRedis(orderNum)){
            System.out.println("EmailListener.fanoutPayMessage: 订单支付中……");
        }else {
            System.out.println("EmailListener.fanoutPayMessage: 订单重复支付，发送邮件");
        }
    }
    public boolean checkOrderFromRedis(String orderNum){
        return redisTemplate.delete(orderNum);
    }
}
